package com.lm.uid.controller;

import com.baidu.fsg.uid.UidGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/uid")
public class UidController {

    @Autowired
    @Qualifier("cachedUidGenerator")
    private UidGenerator uidGenerator;

    @GetMapping("/next")
    public String getUid() {
        long uid = uidGenerator.getUID();
        return "UID = " + uid;
    }

    @GetMapping("/parse/{uid}")
    public String parseUid(@PathVariable long uid) {
        return uidGenerator.parseUID(uid);
    }
}

